package com.loveazure.ui;

import java.util.Vector;

import javax.swing.table.AbstractTableModel;

import com.loveazure.eo.Course;

public class CourseModel extends AbstractTableModel {
	private Vector<Course> data;
	private Vector<String> columnNames;

	public void addRow(Course eo) {
		data.add(eo);
		fireTableDataChanged();
	}

	public CourseModel() {
		data = new Vector<Course>();
		columnNames = new Vector<String>();
		columnNames.add("课程ID");
		columnNames.add("课程名称");
	}

	@Override
	public int getColumnCount() {
		return columnNames.size();
	}

	@Override
	public Class<?> getColumnClass(int columnIndex) {
		return super.getColumnClass(columnIndex);
	}

	@Override
	public boolean isCellEditable(int rowIndex, int columnIndex) {
		return false;
	}

	@Override
	public int getRowCount() {
		return data.size();
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		Course rowdata = data.get(rowIndex);
		if (columnIndex == 0) {
			return rowdata.getId();
		} else {
			return rowdata.getCourseName();
		}
	}

	@Override
	public String getColumnName(int column) {
		return columnNames.get(column);
	}

	public Course getRow(int index) {
		return data.get(index);

	}

	public void removeAll() {
		data.clear();
	}

	public void removeRow(int row) {
		data.remove(row);
		fireTableDataChanged();
	}
}
